Page({
  data: {
    currentCity: ""
  },
  onLoad: function (options) {
    wx.setStorageSync('datas', [])
    var location = wx.getStorageSync('location')
    console.log(location);
    this.setData({
      currentCity: location,
    })
    wx.setStorageSync('citys', location)
  },
  onShow() {
    var city = wx.getStorageSync('citys')
    console.log(city);
    
    var currentCity = wx.getStorageSync("location")
    var storageCity = wx.getStorageSync('citys')
    if (currentCity != storageCity) {
      //询问是否切换城市
      wx.showModal({
        title: '切换城市',
        content: '当时城市不是您所在的城市',
        showCancel: true,
        cancelText: '取消',
        cancelColor: '#000000',
        confirmText: '确定',
        confirmColor: '#3CC51F',
        success: (result) => {
          if (result.confirm) {
            this.setData({
              currentCity
            })
            wx.setStorageSync('citys', currentCity);
          } else {
            this.setData({
              currentCity: storageCity,
            })
          }
        },
        fail: () => {},
        complete: () => {}
      });
    }
  },
  onClick() {
    wx.navigateTo({
      url: '../city/city',
    })
  },
})